<%--
  Created by IntelliJ IDEA.
  User: Nemo
  Date: 2021/6/27
  Time: 23:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"
         import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>Title</title>
    <script src="js/jquery-3.2.1.js"></script>
    <script type="text/javascript">
        function ajax1(){
            var aname=$('#name').val();
            var aage=$('#age').val();
            $.post("ajax/ajax1",{name:aname,age:aage},function (date){
                alert(date);
            });
        }


        function ajax2(){
            var aname=$('#name').val();
            var aage=$('#age').val();
            $.post("ajax/ajax2",{name:aname,age:aage},function (data){
                alert(data.name+" "+data.id);
            });
        }


        function ajax3(){
            $.post("ajax/ajax3",function (data){
                for (var i=0;i<data.length;i++)
                alert(data[i].name+" "+data[i].id);
            });
        }



    </script>
</head>
<body>
姓名<input type="text" id="name"/><br>
年龄<input type="text" id="age"/><br>
<input type="button" value="ajax1提交" onclick="ajax1()"/>
<input type="button" value="ajax2提交" onclick="ajax2()"/>
</body>
</html>
